package org.jeecg.modules.demo.hd.controller;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.demo.hd.entity.AppUserZhifubao;
import org.jeecg.modules.demo.hd.service.IAppUserZhifubaoService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.demo.hd.vo.zhifubao.addZhiFuBaoVo;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;

 /**
 * @Description: 用户支付宝账户
 * @Author: jeecg-boot
 * @Date:   2025-02-09
 * @Version: V1.0
 */
@Api(tags="支付宝账户管理")
@RestController
@RequestMapping("/hd/appUserZhifubao")
@Slf4j
public class AppUserZhifubaoController extends JeecgController<AppUserZhifubao, IAppUserZhifubaoService> {
	@Autowired
	private IAppUserZhifubaoService appUserZhifubaoService;
	
	/**
	 * 分页列表查询
	 *
	 * @param appUserZhifubao
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "app_user_zhifubao-分页列表查询")
	@ApiOperation(value="app_user_zhifubao-分页列表查询", notes="app_user_zhifubao-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<AppUserZhifubao>> queryPageList(AppUserZhifubao appUserZhifubao,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
        QueryWrapper<AppUserZhifubao> queryWrapper = QueryGenerator.initQueryWrapper(appUserZhifubao, req.getParameterMap());
		Page<AppUserZhifubao> page = new Page<AppUserZhifubao>(pageNo, pageSize);
		IPage<AppUserZhifubao> pageList = appUserZhifubaoService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param appUserZhifubao
	 * @return
	 */
	@AutoLog(value = "添加用户支付宝账户")
	@ApiOperation(value="添加用户支付宝账户", notes="添加用户支付宝账户")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody addZhiFuBaoVo appUserZhifubao) {
		this.appUserZhifubaoService.addZhifubao(appUserZhifubao);
		return Result.OK("添加成功！");
	}

	 @AutoLog(value = "获取用户支付宝账户")
	 @ApiOperation(value="获取用户支付宝账户", notes="获取用户支付宝账户")
	 @GetMapping(value = "/queryCurrentZhifubao")
	public Result<String> queryCurrentZhifubao()
	{
		String s = this.appUserZhifubaoService.queryCurrentZhifubao();
		return Result.OK(s);
	}


	 /**
      *  编辑
      *
      * @param appUserZhifubao
      * @return
      */
	@AutoLog(value = "app_user_zhifubao-编辑")
	@ApiOperation(value="app_user_zhifubao-编辑", notes="app_user_zhifubao-编辑")
	@RequiresPermissions("hd:app_user_zhifubao:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody AppUserZhifubao appUserZhifubao) {
		appUserZhifubaoService.updateById(appUserZhifubao);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "app_user_zhifubao-通过id删除")
	@ApiOperation(value="app_user_zhifubao-通过id删除", notes="app_user_zhifubao-通过id删除")
	@RequiresPermissions("hd:app_user_zhifubao:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		appUserZhifubaoService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "app_user_zhifubao-批量删除")
	@ApiOperation(value="app_user_zhifubao-批量删除", notes="app_user_zhifubao-批量删除")
	@RequiresPermissions("hd:app_user_zhifubao:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.appUserZhifubaoService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "app_user_zhifubao-通过id查询")
	@ApiOperation(value="app_user_zhifubao-通过id查询", notes="app_user_zhifubao-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<AppUserZhifubao> queryById(@RequestParam(name="id",required=true) String id) {
		AppUserZhifubao appUserZhifubao = appUserZhifubaoService.getById(id);
		if(appUserZhifubao==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(appUserZhifubao);
	}
}
